TEMPLATE = lib
TARGET = QtFontAwesome
QT += qml quick
CONFIG += plugin c++11

TARGET = $$qtLibraryTarget($$TARGET)
uri = QtFontAwesome
QMAKE_MOC_OPTIONS += -Muri=$$uri

# Input
SOURCES += \
        qtfontawesome_plugin.cpp \
        qfontawesome.cpp

HEADERS += \
        qtfontawesome_plugin.h \
        qfontawesome.h

RESOURCES += \
    fontresource.qrc \
    qmlqrc.qrc

DISTFILES = qmldir
DESTDIR = $$[QT_INSTALL_QML]/$$replace(uri, \., /)

!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
    copy_qmldir.target = $$OUT_PWD/qmldir
    copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir

    copy_plugins_qmltypes.depends = $$_PRO_FILE_PWD_/plugins.qmltypes

    android:equals(QMAKE_HOST.os, Windows) { # 交叉编译，windows 不支持安装功能
        copy_qmldir.target = $$DESTDIR/qmldir
        #在 .pro 文件里路径分隔符都是 /，但在 Windows 中, / 对于 copy 命令有特殊用途，所以需要把 / 替换为 \，否则复制文件会失败
        #多条脚本(命令)之间必须有($$escape_expand(\n\t))分隔,否则报错，“命令语法不正确”
        copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, \\\\)" "$$replace(copy_qmldir.target, /, \\\\)"$$escape_expand(\n\t)

        copy_plugins_qmltypes.target = $$DESTDIR/plugins.qmltypes
        copy_plugins_qmltypes.commands = $(COPY_FILE) "$$replace(copy_plugins_qmltypes.depends, /, \\\\)" "$$replace(copy_plugins_qmltypes.target, /, \\\\)"$$escape_expand(\n\t)

        QMAKE_POST_LINK += $$copy_qmldir.commands # 用 QMAKE_POST_LINK 而不用 QMAKE_PRE_LINK windows 报错：系统找不到指定的路径
        QMAKE_POST_LINK += $$copy_plugins_qmltypes.commands
    } else {
        copy_qmldir.target = $$DESTDIR/qmldir
        copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)"$$escape_expand(\n\t)

        copy_plugins_qmltypes.target = $$DESTDIR/plugins.qmltypes
        copy_plugins_qmltypes.commands = $(COPY_FILE) "$$replace(copy_plugins_qmltypes.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_plugins_qmltypes.target, /, $$QMAKE_DIR_SEP)"$$escape_expand(\n\t)

        QMAKE_EXTRA_TARGETS += copy_qmldir
        QMAKE_EXTRA_TARGETS += copy_plugins_qmltypes

        PRE_TARGETDEPS += $$copy_qmldir.target
        PRE_TARGETDEPS += $$copy_plugins_qmltypes.target

#        QMAKE_PRE_LINK += $$copy_qmldir.commands # 用 QMAKE_POST_LINK 而不用 QMAKE_PRE_LINK windows 报错：系统找不到指定的路径
#        QMAKE_PRE_LINK += $$copy_plugins_qmltypes.commands
    }
}

qmldir.files = qmldir
unix:!equals(QMAKE_HOST.os, Windows) { # 交叉编译，windows 不支持安装功能
    installPath = $$[QT_INSTALL_QML]/$$replace(uri, \., /)
    qmldir.path = $$installPath
    target.path = $$installPath
    INSTALLS += target qmldir
}

win32 {
    copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
    copy_qmldir.target = $$[QT_INSTALL_QML]/$$replace(uri, \., /)/qmldir
    #在 .pro 文件里路径分隔符都是 /，但在 Windows 中, / 对于 copy 命令有特殊用途，所以需要把 / 替换为 \，否则复制文件会失败
    copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, \\\\)" "$$replace(copy_qmldir.target, /, \\\\)"$$escape_expand(\n\t)

    copy_plugins_qmltypes.depends = $$_PRO_FILE_PWD_/plugins.qmltypes
    copy_plugins_qmltypes.target = $$[QT_INSTALL_QML]/$$replace(uri, \., /)/plugins.qmltypes
    copy_plugins_qmltypes.commands = $(COPY_FILE) "$$replace(copy_plugins_qmltypes.depends, /, \\\\)" "$$replace(copy_plugins_qmltypes.target, /, \\\\)"$$escape_expand(\n\t)

    QMAKE_POST_LINK += $$copy_qmldir.commands
    QMAKE_POST_LINK += $$copy_plugins_qmltypes.commands
}
